package io.ede.modules.ede.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;
import io.ede.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.ede.modules.ede.entity.SysAttrConfigEntity;
import io.ede.modules.ede.service.SysAttrConfigService;
import io.ede.common.utils.PageUtils;
import io.ede.common.utils.R;



/**
 * 
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-09-18 16:35:50
 */
@RestController
@RequestMapping("ede/sysattrconfig")
public class SysAttrConfigController {
    @Autowired
    private SysAttrConfigService sysAttrConfigService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("ede:sysattrconfig:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysAttrConfigService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("ede:sysattrconfig:info")
    public R info(@PathVariable("id") Integer id){
        SysAttrConfigEntity sysAttrConfig = sysAttrConfigService.getById(id);

        return R.ok().put("sysAttrConfig", sysAttrConfig);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("ede:sysattrconfig:save")
    public R save(@RequestBody SysAttrConfigEntity sysAttrConfig){
        sysAttrConfigService.save(sysAttrConfig);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("ede:sysattrconfig:update")
    public R update(@RequestBody SysAttrConfigEntity sysAttrConfig){
        ValidatorUtils.validateEntity(sysAttrConfig);
        sysAttrConfig.setUpdateTime(new Date());
        sysAttrConfigService.updateById(sysAttrConfig);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("ede:sysattrconfig:delete")
    public R delete(@RequestBody Integer[] ids){
        sysAttrConfigService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
